package com.yst.metho.web.application.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

public abstract class AbstractSuiviTableModel extends AbstractSortableTableModel
{
	protected Collection mList;

	private AbstractSuiviComparator comparator;

	public int getRowCount()
	{
		int retour = 0;
		if (null != mList)
		{
			retour = mList.size();
		}
		return retour;
	}

	public Object getValueAt(int column, int row)
	{
		Object retour = null;
		Iterator it = mList.iterator();
		int i = -1;
		do
		{
			retour = it.next();
			i++;
		}
		while (i != row);
		return retour;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.yst.metho.web.application.utils.AbstractSortableTableModel#setSortableColumn(int)
	 */
	public void setSortableColumn(int column)
	{
		comparator.setColumn(column);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.yst.metho.web.application.utils.AbstractSortableTableModel#sort()
	 */
	public void sort()
	{
		Collections.sort((ArrayList) mList, comparator);
		fireTableDataChanged();
	}

	/**
	 * @return the comparator
	 */
	protected AbstractSuiviComparator getComparator()
	{
		return comparator;
	}

	/**
	 * @param comparator
	 *            the comparator to set
	 */
	protected void setComparator(AbstractSuiviComparator comparator)
	{
		this.comparator = comparator;
	}

	/* (non-Javadoc)
	 * @see com.yst.metho.web.application.interfaces.IListingViewModel#isAscending()
	 */
	public boolean isAscending()
	{
		return comparator.isAscending();
	}
	
	
}
